package SecondeStage.FanXing;

import java.util.*;

@SuppressWarnings({"all"})
public class GenericExercise {
    public static void main(String[] args) {
        // 使用泛型方式给HashSet放入3个student对象
        HashSet<Student> students =new HashSet<Student>();
        students.add(new Student("jack",18));
        students.add(new Student("tom",19));
        students.add(new Student("mary",20));

        for (Student student :students) {
            System.out.println(student);
        }

        HashMap<String,Student> hm = new HashMap<String,Student>();
        hm.put("jack",new Student("jack",18));
        hm.put("tom",new Student("tom",19));
        hm.put("mary",new Student("mary",20));
        // 迭代器遍历 EntrySet
        Set<Map.Entry<String,Student>> entries =hm.entrySet();
        Iterator<Map.Entry<String, Student>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
        }
    }
}

class Student{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}